﻿#region  文件信息

// ---------------------------------------------------------------------------------------
// <copyright file="HostController.cs" company="">
// 作者：李帅伦
// </copyright>
// <summary>
// 类型简介：
// 类型详细：HostController.cs
// 创建时间：2014-12-25 18:24
// 修改时间：2014-12-10 16:30
// </summary>
// ---------------------------------------------------------------------------------------
#endregion

using WebCommon.Com;

namespace OneAdmin.Controllers
{
    #region

    using System;
    using System.Web;
    using System.Web.Mvc;

    using OneAdmin.Models.PostModels;

    using Payment.Albaba.Com;
   
    using Payment.Albaba.PcCode;
    using Payment.Weixin;

    using WebCommon;
    using WebCommon.Extensions;
    using WebCommon.Up;

    #endregion

    /// <summary>
    /// The host controller.
    /// </summary>
    public class HostController : Controller
    {
        public ActionResult Ho()
        {
            return this.Content(Request.Url.Authority);
        }

        #region Public Methods and Operators

        /// <summary>
        /// 微信配置文件
        /// </summary>
        /// <returns>
        /// The <see cref="WxConfig"/>.
        /// </returns>
        [NonAction]
        public WxConfig GetWxConfig()
        {
            var wxConfig = new WxConfig();
            wxConfig.AppId = "wx53f182f19b9afdab";
            wxConfig.Appkey =
                "3916C2g469K3lHvKFyKMutf7yHWDW0zRkN31mQ5FsJieib79jiCImUo7JdKeEdL5mwCPwmpTW5qkgTnQFq0RkC2sfkAxNKq1L3Gd3YlUEs89jl8hDT1AXM8FzCCbeSGf";
            wxConfig.PartnerKey = "bfe5cc43c8ee32a1416bb9027f97c025";
            wxConfig.Partner = "1219356801";
            return wxConfig;
        }

        // GET: /Host/

        /// <summary>
        /// The index.
        /// </summary>
        /// <returns>
        /// The <see cref="ActionResult"/>.
        /// </returns>
        public ActionResult Index()
        {
            return this.View();
        }

        /// <summary>
        /// 微信通知url
        /// </summary>
        /// <returns>
        /// The <see cref="ActionResult"/>.
        /// </returns>
        /// <exception cref="NotImplementedException">
        /// </exception>
        public ActionResult NotifyUrl()
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// 上传页面
        /// </summary>
        /// <returns>
        /// The <see cref="ActionResult"/>.
        /// </returns>
        public ActionResult Up()
        {
            return this.View();
        }

        /// <summary>
        /// 上传post
        /// </summary>
        /// <param name="hb">
        /// </param>
        /// <returns>
        /// The <see cref="JsonResult"/>.
        /// </returns>
        [HttpPost]
        public JsonResult Upload(HttpPostedFileBase hb)
        {
            var uploadImg = new UploadImg(hb, this.Server.MapPath("")); 
            // 保存文件名字
            uploadImg.SaFileName = Guid.NewGuid().ToString();
            var save = uploadImg.Save();
            if (save)
            {
                uploadImg.Compress(this.Server.MapPath("~/up/" + uploadImg.SaFileName + ".jpg"));
            }

            return this.Json(new { upImgFileName = uploadImg.SaPath, ms = save });
        }

        /// <summary>
        /// 微信支付
        /// </summary>
        /// <returns>
        /// The <see cref="ActionResult"/>.
        /// </returns>
        public ActionResult Weixin()
        {
            var order = new PayOrder();
            var wxPackage = new WxPackage(order, this.GetWxConfig());
            wxPackage.SpbillCreateIp = this.Request.UserHostAddress;

            var wxResponseJsApi = new WxResponseJsApi(this.GetWxConfig(), wxPackage);
            //wxResponseJsApi.NotifyUrl = this.Url.Action("NotifyUrl");

            string fasong = wxResponseJsApi.Fasong();

            return new JsonReturn(fasong);
        }

        /// <summary>
        /// 验证码
        /// </summary>
        /// <returns>
        /// The <see cref="ActionResult"/>.
        /// </returns>
        public ActionResult Yzm()
        {
            var vc = new VerifyCodeImage();
            var randomsAzNum = new RandomsAzNum(4);
            randomsAzNum.Ex = randomsAzNum.GetAzLower + randomsAzNum.GetNum + randomsAzNum.GetAzUpper;
            randomsAzNum.Length = 4;
            return this.File(vc.CreateImageOnPage(randomsAzNum.OutputEx()), "img");
        }

        /// <summary>
        /// 支付宝测试
        /// </summary>
        /// <returns>
        /// The <see cref="ActionResult"/>.
        /// </returns>
        public ActionResult Zhifubao()
        {
            var aliPayConfig = new AliConfig("2088412959027467", "jbx2xml1asuwhit1rlgyn894xd61fjgf");
            aliPayConfig.ReturnUrl = "http://asd.www.com/asdd";
            aliPayConfig.NotifyUrl = "http://asd.www.com/asdd";
            var aliPayService = new AliPayService(new PayOrder(), new AliSeller());
       
            var alp = new AliSub(aliPayConfig, aliPayService);
            var fasong = alp.Fasong();
            return this.Content(fasong);
        }

        /// <summary>
        /// 二维码
        /// </summary>
        /// <returns></returns>
        public ActionResult Qr(string s)
        {
            return this.View();
        }
        #endregion
    }
}